package com.ruoyi.mk.controller;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.annotation.Anonymous;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.mk.domain.MkNjpk;
import com.ruoyi.mk.domain.MkOrigin;
import com.ruoyi.mk.mapper.MkNjpkMapper;
import com.ruoyi.mk.service.IMkOriginService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TableDataInfo;

import java.util.List;


/**
 * 始发地Controller
 * @author ruoyi
 * @date 2025-06-24
 */
@RestController
@RequestMapping("/system/origin")
public class MkOriginController extends BaseController {

    @Autowired
    private IMkOriginService mkOriginService;
    @Resource
    private MkNjpkMapper mkNjpkMapper;

    @Anonymous
    @PostMapping("/getPrice")
    public AjaxResult getPrice(@RequestParam(value = "category") String category,@RequestParam("density") Double density,@RequestParam("priceTable") String priceTable)
    {
        MkNjpk mkNjpk=mkNjpkMapper.selectByDensity(density);
        String dw="$/kg";
        if(density<100){
            dw="$/m³";
        }
        switch (priceTable) {
            case "rybh":
                if(category.equals("almt")){
                    return AjaxResult.success("成功",mkNjpk.getrybhA()+dw);
                }else if(category.equals("msk")){
                    return AjaxResult.success("成功",mkNjpk.getrybhM()+dw);
                }
                break;
            case "wjgj":
                if(category.equals("almt")){
                    return AjaxResult.success("成功",mkNjpk.getwjgjA()+dw);
                }else if(category.equals("msk")){
                    return AjaxResult.success("成功",mkNjpk.getwjgjM()+dw);
                }
                break;
            case "jxsb":
                if(category.equals("almt")){
                    return AjaxResult.success("成功",mkNjpk.getjxsbA()+dw);
                }else if(category.equals("msk")){
                    return AjaxResult.success("成功",mkNjpk.getjxsbM()+dw);
                }
                break;
            case "jd":
                if(category.equals("almt")){
                    return AjaxResult.success("成功",mkNjpk.getjdA()+dw);
                }else if(category.equals("msk")){
                    return AjaxResult.success("成功",mkNjpk.getjdM()+dw);
                }
                break;
            case "jj":
                if(category.equals("almt")){
                    return AjaxResult.success("成功",mkNjpk.getjjA()+dw);
                }else if(category.equals("msk")){
                    return AjaxResult.success("成功",mkNjpk.getjjM()+dw);
                }
                break;
            case "wj":
                if(density<250){
                    dw="$/m³";
                }
                if(category.equals("almt")){
                    return AjaxResult.success("成功",mkNjpk.getwjA()+dw);
                }else if(category.equals("msk")){
                    return AjaxResult.success("成功",mkNjpk.getwjM()+dw);
                }
                break;
            case "jzcl":
                if(category.equals("almt")){
                    return AjaxResult.success("成功",mkNjpk.getjzclA()+dw);
                }else if(category.equals("msk")){
                    return AjaxResult.success("成功",mkNjpk.getjzclM()+dw);
                }
                break;
            case "ylqx":
                if(category.equals("almt")){
                    return AjaxResult.success("成功",mkNjpk.getylqxA()+dw);
                }else if(category.equals("msk")){
                    return AjaxResult.success("成功",mkNjpk.getylqxM()+dw);
                }
                break;
            case "qcpj":
                if(category.equals("almt")){
                    return AjaxResult.success("成功",mkNjpk.getqcpjA()+dw);
                }else if(category.equals("msk")){
                    return AjaxResult.success("成功",mkNjpk.getqcpjM()+dw);
                }
                break;
            case "hzp":
                if(category.equals("almt")){
                    return AjaxResult.success("成功",mkNjpk.gethzpA()+dw);
                }else if(category.equals("msk")){
                    return AjaxResult.success("成功",mkNjpk.gethzpM()+dw);
                }
                break;
            case "fz":
                if(category.equals("almt")){
                    return AjaxResult.success("成功",mkNjpk.getfzA()+dw);
                }else if(category.equals("msk")){
                    return AjaxResult.success("成功",mkNjpk.getfzM()+dw);
                }
                break;
            case "sp":
                if(category.equals("almt")){
                    return AjaxResult.success("成功",mkNjpk.getspA()+dw);
                }else if(category.equals("msk")){
                    return AjaxResult.success("成功",mkNjpk.getspM()+dw);
                }
                break;
            default:
                return AjaxResult.error("请选择平类");
        }
        return AjaxResult.error("网络繁忙");
    }

    /**
     * 查询始发地列表
     */
//    @PreAuthorize("@ss.hasPermi('system:origin:list')")
    @Anonymous
    @GetMapping("/list")
    public TableDataInfo list(MkOrigin mkOrigin)
    {
//        startPage();
        List<MkOrigin> list = mkOriginService.selectMkOriginList(mkOrigin);
        return getDataTable(list);
    }

    /**
     * 导出始发地列表
     */
//    @PreAuthorize("@ss.hasPermi('system:origin:export')")
    @Log(title = "始发地", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MkOrigin mkOrigin)
    {
        List<MkOrigin> list = mkOriginService.selectMkOriginList(mkOrigin);
        ExcelUtil<MkOrigin> util = new ExcelUtil<MkOrigin>(MkOrigin.class);
        util.exportExcel(response, list, "始发地数据");
    }

    /**
     * 获取始发地详细信息
     */
//    @PreAuthorize("@ss.hasPermi('system:origin:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(mkOriginService.selectMkOriginById(id));
    }

    /**
     * 新增始发地
     */
//    @PreAuthorize("@ss.hasPermi('system:origin:add')")
    @Log(title = "始发地", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody MkOrigin mkOrigin)
    {
        return toAjax(mkOriginService.insertMkOrigin(mkOrigin));
    }

    /**
     * 修改始发地
     */
//    @PreAuthorize("@ss.hasPermi('system:origin:edit')")
    @Log(title = "始发地", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody MkOrigin mkOrigin)
    {
        return toAjax(mkOriginService.updateMkOrigin(mkOrigin));
    }

    /**
     * 删除始发地
     */
//    @PreAuthorize("@ss.hasPermi('system:origin:remove')")
    @Log(title = "始发地", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(mkOriginService.deleteMkOriginByIds(ids));
    }
}
